package io.gitee.thghh.generate.core.entity.table;

import com.mybatisflex.core.query.QueryColumn;
import com.mybatisflex.core.table.TableDef;


/**
 * 数据源配置 表定义层。
 *
 * @author pengzhikang
 * @since 2025-03-27
 */
public class DatasourceConfigTableDef extends TableDef {

    private static final long serialVersionUID = 1L;

    /**
     * 数据源配置
     */
    public static final DatasourceConfigTableDef DATASOURCE_CONFIG = new DatasourceConfigTableDef();

    /**
     * 主键
     */
    public final QueryColumn ID = new QueryColumn(this, "ID");

    /**
     * 主机
     */
    public final QueryColumn HOST = new QueryColumn(this, "HOST");

    /**
     * 数据源名称
     */
    public final QueryColumn NAME = new QueryColumn(this, "NAME");

    /**
     * 端口
     */
    public final QueryColumn PORT = new QueryColumn(this, "PORT");

    /**
     * 数据库名称
     */
    public final QueryColumn DB_NAME = new QueryColumn(this, "DB_NAME");

    /**
     * 数据库方言
     */
    public final QueryColumn DIALECT = new QueryColumn(this, "DIALECT");

    /**
     * 密码
     */
    public final QueryColumn PASSWORD = new QueryColumn(this, "PASSWORD");

    /**
     * 用户名
     */
    public final QueryColumn USER_NAME = new QueryColumn(this, "USER_NAME");

    /**
     * 删除标记
     */
    public final QueryColumn DELETE_FLAG = new QueryColumn(this, "DELETE_FLAG");

    /**
     * 数据库模式
     */
    public final QueryColumn SCHEMA_NAME = new QueryColumn(this, "SCHEMA_NAME");

    /**
     * 创建时间
     */
    public final QueryColumn CREATED_DATE = new QueryColumn(this, "CREATED_DATE");

    /**
     * 数据库驱动类
     */
    public final QueryColumn DRIVER_CLASS = new QueryColumn(this, "DRIVER_CLASS");

    /**
     * 最后更新时间
     */
    public final QueryColumn MODIFIED_DATE = new QueryColumn(this, "MODIFIED_DATE");

    /**
     * 所有字段。
     */
    public final QueryColumn ALL_COLUMNS = new QueryColumn(this, "*");

    /**
     * 默认字段，不包含逻辑删除或者 large 等字段。
     */
    public final QueryColumn[] DEFAULT_COLUMNS = new QueryColumn[]{ID, NAME, DIALECT, DRIVER_CLASS, SCHEMA_NAME, DB_NAME, HOST, PORT, USER_NAME, PASSWORD, DELETE_FLAG, CREATED_DATE, MODIFIED_DATE};

    public DatasourceConfigTableDef() {
        super("", "DATASOURCE_CONFIG");
    }

    private DatasourceConfigTableDef(String schema, String name, String alisa) {
        super(schema, name, alisa);
    }

    public DatasourceConfigTableDef as(String alias) {
        String key = getNameWithSchema() + "." + alias;
        return getCache(key, k -> new DatasourceConfigTableDef("", "DATASOURCE_CONFIG", alias));
    }

}
